package com.whmskj.xjlhsc.controller;

import com.whmskj.xjlhsc.controller.vo.Result;
import com.whmskj.xjlhsc.service.EnergyKbService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;

/**
 * 能耗看板控制器
 * 专门处理能耗相关的数据查询接口
 * 
 * @author zn
 * @since 2025-08-15
 */
@Api(tags = "能耗看板管理")
@RestController
@RequestMapping("/api/energyConsumption")
@CrossOrigin
@Slf4j
public class EnergyKbController {

    @Autowired
    private EnergyKbService energyConsumptionService;

    /**
     * 左上角「近一周班组耗电占比」——近7天按天的早/晚班能耗
     * 数据源：shachang_sb_Energy_dissipation_shift
     */
    @GetMapping("/shift/last7days")
    @ApiOperation("近7天早/晚班能耗（日）")
    public Result last7DaysShiftEnergy() {
        return Result.success(energyConsumptionService.getLast7DaysShiftEnergy());
    }

    /**
     * 各工序能耗概览：返回昨日/本周/本月(盘存月)/本年四列
     */
    @GetMapping("/process/energy")
    @ApiOperation("各工序能耗概览（昨日/本周/本月/本年）")
    public Result processEnergy(
            @RequestParam(required = false) @org.springframework.format.annotation.DateTimeFormat(pattern = "yyyy-MM-dd") java.time.LocalDate day) {
        return Result.success(energyConsumptionService.getProcessEnergyOverview(day));
    }

    /**
     * 车间耗电量趋势（日=近7日，周=近7周，月=近7个盘存月）
     */
    @GetMapping("/workshop/trend")
    @ApiOperation("车间耗电量趋势")
    public Result workshopTrend(
            @RequestParam String period,
            @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate day) {
        return Result.success(energyConsumptionService.getWorkshopTrend(period, day));
    }

}